<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		
		<script>
			// 1.练习四:定义函数,传入一个n,计算1-n的和
			function calcNSum(n){
				var total = 0;
				for(var i=1;i<=n;i++){
					console.log(i);
					total += i;
				}
				return total;
			}
			var result1 = calcNSum(5);
			var result2 = calcNSum(100);
			console.log(result1);
			console.log(result2);
					
			// 2.练习五:定义一个函数,传入一个数组,对数组进行反转
			// var nums = [10, 14, 8, 5, 88];
			// for(var i=0;i<nums.length/2;i++){
			// 	var temp = nums[i];
			// 	nums[i] = nums[nums.length-1-i];
			// 	nums[nums.length-1-i] = temp;
			// }
			// console.log(nums);
			function reverseArray(arr){
				for(var i=0;i<arr.length/2;i++){
					var temp = arr[i];
					arr[i] = arr[arr.length-1-i];
					arr[arr.length-1-i] = temp;
				}
				return arr;
			}
			
			var nums1 = [10, 14, 8, 5, 88];
			nums1 = reverseArray(nums1);
			console.log(nums1);
			var nums2 = [20, 76, 44, 67, 23];
			nums2 = reverseArray(nums2);
			console.log(nums2);
		</script>
	</body>
</html>
